﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using HY.Model;
namespace HY.BLL
{
    /// <summary>
    /// staff
    /// </summary>
    public partial class staff
    {
        private readonly HY.DAL.staff dal = new HY.DAL.staff();
        public staff()
        { }
        #region  Method

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(HY.Model.staff model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(HY.Model.staff model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete()
        {
            //该表无主键信息，请自定义主键/条件字段
            return dal.Delete();
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HY.Model.staff GetModel()
        {
            //该表无主键信息，请自定义主键/条件字段
            return dal.GetModel();
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public HY.Model.staff GetModelByCache()
        {
            //该表无主键信息，请自定义主键/条件字段
            string CacheKey = "staffModel-";
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel();
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (HY.Model.staff)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<HY.Model.staff> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<HY.Model.staff> DataTableToList(DataTable dt)
        {
            List<HY.Model.staff> modelList = new List<HY.Model.staff>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                HY.Model.staff model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new HY.Model.staff();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = new Guid(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["account"] != null && dt.Rows[n]["account"].ToString() != "")
                    {
                        model.account = dt.Rows[n]["account"].ToString();
                    }
                    if (dt.Rows[n]["pwd"] != null && dt.Rows[n]["pwd"].ToString() != "")
                    {
                        model.pwd = dt.Rows[n]["pwd"].ToString();
                    }
                    if (dt.Rows[n]["name"] != null && dt.Rows[n]["name"].ToString() != "")
                    {
                        model.name = dt.Rows[n]["name"].ToString();
                    }
                    if (dt.Rows[n]["phone"] != null && dt.Rows[n]["phone"].ToString() != "")
                    {
                        model.phone = dt.Rows[n]["phone"].ToString();
                    }
                    if (dt.Rows[n]["created_on"] != null && dt.Rows[n]["created_on"].ToString() != "")
                    {
                        model.created_on = DateTime.Parse(dt.Rows[n]["created_on"].ToString());
                    }
                    if (dt.Rows[n]["created_by"] != null && dt.Rows[n]["created_by"].ToString() != "")
                    {
                        model.created_by = dt.Rows[n]["created_by"].ToString();
                    }
                    if (dt.Rows[n]["changed_on"] != null && dt.Rows[n]["changed_on"].ToString() != "")
                    {
                        model.changed_on = DateTime.Parse(dt.Rows[n]["changed_on"].ToString());
                    }
                    if (dt.Rows[n]["changed_by"] != null && dt.Rows[n]["changed_by"].ToString() != "")
                    {
                        model.changed_by = dt.Rows[n]["changed_by"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

